<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="图片" prop="picture">
        <el-input
          v-model="queryParams.picture"
          placeholder="请输入图片"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="等级" prop="level">
        <el-input
          v-model="queryParams.level"
          placeholder="请输入等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="介绍" prop="lore">
        <el-input
          v-model="queryParams.lore"
          placeholder="请输入介绍"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="效果" prop="effect">
        <el-input
          v-model="queryParams.effect"
          placeholder="请输入效果"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="佩戴条件" prop="wearingConditions">
        <el-input
          v-model="queryParams.wearingConditions"
          placeholder="请输入佩戴条件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="佩戴条件值" prop="conditionVaule">
        <el-input
          v-model="queryParams.conditionVaule"
          placeholder="请输入佩戴条件值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打造所需银两" prop="tael">
        <el-input
          v-model="queryParams.tael"
          placeholder="请输入打造所需银两"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打造所需材料" prop="material">
        <el-input
          v-model="queryParams.material"
          placeholder="请输入打造所需材料"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="兵力" prop="troops">
        <el-input
          v-model="queryParams.troops"
          placeholder="请输入兵力"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="精力" prop="energy">
        <el-input
          v-model="queryParams.energy"
          placeholder="请输入精力"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="防御力" prop="defenseCapability">
        <el-input
          v-model="queryParams.defenseCapability"
          placeholder="请输入防御力"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="攻击" prop="attack">
        <el-input
          v-model="queryParams.attack"
          placeholder="请输入攻击"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="速度" prop="speed">
        <el-input
          v-model="queryParams.speed"
          placeholder="请输入速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="命中率" prop="hitRate">
        <el-input
          v-model="queryParams.hitRate"
          placeholder="请输入命中率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="暴击率" prop="criticalHitRate">
        <el-input
          v-model="queryParams.criticalHitRate"
          placeholder="请输入暴击率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="反击率" prop="counterattackRate">
        <el-input
          v-model="queryParams.counterattackRate"
          placeholder="请输入反击率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="致命率" prop="fatalityRate">
        <el-input
          v-model="queryParams.fatalityRate"
          placeholder="请输入致命率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法暴率" prop="lawViolenceRate">
        <el-input
          v-model="queryParams.lawViolenceRate"
          placeholder="请输入法暴率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="反震率" prop="antiSeismicRate">
        <el-input
          v-model="queryParams.antiSeismicRate"
          placeholder="请输入反震率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="闪避率" prop="dodgeChance">
        <el-input
          v-model="queryParams.dodgeChance"
          placeholder="请输入闪避率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抗物理" prop="antiPhysics">
        <el-input
          v-model="queryParams.antiPhysics"
          placeholder="请输入抗物理"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抗玄击" prop="antiXuanStrike">
        <el-input
          v-model="queryParams.antiXuanStrike"
          placeholder="请输入抗玄击"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抗封锁" prop="antiBlocking">
        <el-input
          v-model="queryParams.antiBlocking"
          placeholder="请输入抗封锁"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抗扰乱" prop="antiDisturbance">
        <el-input
          v-model="queryParams.antiDisturbance"
          placeholder="请输入抗扰乱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抗围困" prop="antiSiege">
        <el-input
          v-model="queryParams.antiSiege"
          placeholder="请输入抗围困"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抗风沙" prop="antiWind">
        <el-input
          v-model="queryParams.antiWind"
          placeholder="请输入抗风沙"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抗妖火" prop="antiFire">
        <el-input
          v-model="queryParams.antiFire"
          placeholder="请输入抗妖火"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抗毒术" prop="antiToxic">
        <el-input
          v-model="queryParams.antiToxic"
          placeholder="请输入抗毒术"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抗落雷" prop="antiLightning">
        <el-input
          v-model="queryParams.antiLightning"
          placeholder="请输入抗落雷"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="价格" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:equipmentpresets:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:equipmentpresets:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:equipmentpresets:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:equipmentpresets:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="equipmentpresetsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="图片" align="center" prop="picture" />
      <el-table-column label="等级" align="center" prop="level" />
      <el-table-column label="部位" align="center" prop="type" />
      <el-table-column label="介绍" align="center" prop="lore" />
      <el-table-column label="效果" align="center" prop="effect" />
      <el-table-column label="佩戴条件" align="center" prop="wearingConditions" />
      <el-table-column label="佩戴条件值" align="center" prop="conditionVaule" />
      <el-table-column label="打造所需银两" align="center" prop="tael" />
      <el-table-column label="打造所需材料" align="center" prop="material" />
      <el-table-column label="兵力" align="center" prop="troops" />
      <el-table-column label="精力" align="center" prop="energy" />
      <el-table-column label="防御力" align="center" prop="defenseCapability" />
      <el-table-column label="攻击" align="center" prop="attack" />
      <el-table-column label="速度" align="center" prop="speed" />
      <el-table-column label="命中率" align="center" prop="hitRate" />
      <el-table-column label="暴击率" align="center" prop="criticalHitRate" />
      <el-table-column label="反击率" align="center" prop="counterattackRate" />
      <el-table-column label="致命率" align="center" prop="fatalityRate" />
      <el-table-column label="法暴率" align="center" prop="lawViolenceRate" />
      <el-table-column label="反震率" align="center" prop="antiSeismicRate" />
      <el-table-column label="闪避率" align="center" prop="dodgeChance" />
      <el-table-column label="抗物理" align="center" prop="antiPhysics" />
      <el-table-column label="抗玄击" align="center" prop="antiXuanStrike" />
      <el-table-column label="抗封锁" align="center" prop="antiBlocking" />
      <el-table-column label="抗扰乱" align="center" prop="antiDisturbance" />
      <el-table-column label="抗围困" align="center" prop="antiSiege" />
      <el-table-column label="抗风沙" align="center" prop="antiWind" />
      <el-table-column label="抗妖火" align="center" prop="antiFire" />
      <el-table-column label="抗毒术" align="center" prop="antiToxic" />
      <el-table-column label="抗落雷" align="center" prop="antiLightning" />
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:equipmentpresets:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:equipmentpresets:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改装备预设对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="图片" prop="picture">
          <el-input v-model="form.picture" placeholder="请输入图片" />
        </el-form-item>
        <el-form-item label="等级" prop="level">
          <el-input v-model="form.level" placeholder="请输入等级" />
        </el-form-item>
        <el-form-item label="介绍" prop="lore">
          <el-input v-model="form.lore" placeholder="请输入介绍" />
        </el-form-item>
        <el-form-item label="效果" prop="effect">
          <el-input v-model="form.effect" placeholder="请输入效果" />
        </el-form-item>
        <el-form-item label="佩戴条件" prop="wearingConditions">
          <el-input v-model="form.wearingConditions" placeholder="请输入佩戴条件" />
        </el-form-item>
        <el-form-item label="佩戴条件值" prop="conditionVaule">
          <el-input v-model="form.conditionVaule" placeholder="请输入佩戴条件值" />
        </el-form-item>
        <el-form-item label="打造所需银两" prop="tael">
          <el-input v-model="form.tael" placeholder="请输入打造所需银两" />
        </el-form-item>
        <el-form-item label="打造所需材料" prop="material">
          <el-input v-model="form.material" placeholder="请输入打造所需材料" />
        </el-form-item>
        <el-form-item label="兵力" prop="troops">
          <el-input v-model="form.troops" placeholder="请输入兵力" />
        </el-form-item>
        <el-form-item label="精力" prop="energy">
          <el-input v-model="form.energy" placeholder="请输入精力" />
        </el-form-item>
        <el-form-item label="防御力" prop="defenseCapability">
          <el-input v-model="form.defenseCapability" placeholder="请输入防御力" />
        </el-form-item>
        <el-form-item label="攻击" prop="attack">
          <el-input v-model="form.attack" placeholder="请输入攻击" />
        </el-form-item>
        <el-form-item label="速度" prop="speed">
          <el-input v-model="form.speed" placeholder="请输入速度" />
        </el-form-item>
        <el-form-item label="命中率" prop="hitRate">
          <el-input v-model="form.hitRate" placeholder="请输入命中率" />
        </el-form-item>
        <el-form-item label="暴击率" prop="criticalHitRate">
          <el-input v-model="form.criticalHitRate" placeholder="请输入暴击率" />
        </el-form-item>
        <el-form-item label="反击率" prop="counterattackRate">
          <el-input v-model="form.counterattackRate" placeholder="请输入反击率" />
        </el-form-item>
        <el-form-item label="致命率" prop="fatalityRate">
          <el-input v-model="form.fatalityRate" placeholder="请输入致命率" />
        </el-form-item>
        <el-form-item label="法暴率" prop="lawViolenceRate">
          <el-input v-model="form.lawViolenceRate" placeholder="请输入法暴率" />
        </el-form-item>
        <el-form-item label="反震率" prop="antiSeismicRate">
          <el-input v-model="form.antiSeismicRate" placeholder="请输入反震率" />
        </el-form-item>
        <el-form-item label="闪避率" prop="dodgeChance">
          <el-input v-model="form.dodgeChance" placeholder="请输入闪避率" />
        </el-form-item>
        <el-form-item label="抗物理" prop="antiPhysics">
          <el-input v-model="form.antiPhysics" placeholder="请输入抗物理" />
        </el-form-item>
        <el-form-item label="抗玄击" prop="antiXuanStrike">
          <el-input v-model="form.antiXuanStrike" placeholder="请输入抗玄击" />
        </el-form-item>
        <el-form-item label="抗封锁" prop="antiBlocking">
          <el-input v-model="form.antiBlocking" placeholder="请输入抗封锁" />
        </el-form-item>
        <el-form-item label="抗扰乱" prop="antiDisturbance">
          <el-input v-model="form.antiDisturbance" placeholder="请输入抗扰乱" />
        </el-form-item>
        <el-form-item label="抗围困" prop="antiSiege">
          <el-input v-model="form.antiSiege" placeholder="请输入抗围困" />
        </el-form-item>
        <el-form-item label="抗风沙" prop="antiWind">
          <el-input v-model="form.antiWind" placeholder="请输入抗风沙" />
        </el-form-item>
        <el-form-item label="抗妖火" prop="antiFire">
          <el-input v-model="form.antiFire" placeholder="请输入抗妖火" />
        </el-form-item>
        <el-form-item label="抗毒术" prop="antiToxic">
          <el-input v-model="form.antiToxic" placeholder="请输入抗毒术" />
        </el-form-item>
        <el-form-item label="抗落雷" prop="antiLightning">
          <el-input v-model="form.antiLightning" placeholder="请输入抗落雷" />
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入价格" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEquipmentpresets, getEquipmentpresets, delEquipmentpresets, addEquipmentpresets, updateEquipmentpresets } from "@/api/system/equipmentpresets"

export default {
  name: "Equipmentpresets",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 装备预设表格数据
      equipmentpresetsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        picture: null,
        level: null,
        type: null,
        lore: null,
        effect: null,
        wearingConditions: null,
        conditionVaule: null,
        tael: null,
        material: null,
        troops: null,
        energy: null,
        defenseCapability: null,
        attack: null,
        speed: null,
        hitRate: null,
        criticalHitRate: null,
        counterattackRate: null,
        fatalityRate: null,
        lawViolenceRate: null,
        antiSeismicRate: null,
        dodgeChance: null,
        antiPhysics: null,
        antiXuanStrike: null,
        antiBlocking: null,
        antiDisturbance: null,
        antiSiege: null,
        antiWind: null,
        antiFire: null,
        antiToxic: null,
        antiLightning: null,
        price: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "名称不能为空", trigger: "blur" }
        ],
        picture: [
          { required: true, message: "图片不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询装备预设列表 */
    getList() {
      this.loading = true
      listEquipmentpresets(this.queryParams).then(response => {
        this.equipmentpresetsList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        picture: null,
        level: null,
        type: null,
        lore: null,
        effect: null,
        wearingConditions: null,
        conditionVaule: null,
        tael: null,
        material: null,
        troops: null,
        energy: null,
        defenseCapability: null,
        attack: null,
        speed: null,
        hitRate: null,
        criticalHitRate: null,
        counterattackRate: null,
        fatalityRate: null,
        lawViolenceRate: null,
        antiSeismicRate: null,
        dodgeChance: null,
        antiPhysics: null,
        antiXuanStrike: null,
        antiBlocking: null,
        antiDisturbance: null,
        antiSiege: null,
        antiWind: null,
        antiFire: null,
        antiToxic: null,
        antiLightning: null,
        price: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加装备预设"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getEquipmentpresets(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改装备预设"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEquipmentpresets(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addEquipmentpresets(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除装备预设编号为"' + ids + '"的数据项？').then(function() {
        return delEquipmentpresets(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/equipmentpresets/export', {
        ...this.queryParams
      }, `equipmentpresets_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
